package com.sky.city;

import android.graphics.Color;
import android.os.Build;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.RequiresApi;

import com.common.baselibrary.mvp.BaseMvpActivity;
import com.common.baselibrary.rxjava2.utils.JSONReqParams;
import com.finddreams.languagelib.MultiLanguageUtil;
import com.gyf.immersionbar.ImmersionBar;
import com.sky.city.dialog.LanguageDialog;
import com.sky.city.fragment.FiveFragment;
import com.sky.city.fragment.FourFragment;
import com.sky.city.fragment.HomeFragment;
import com.sky.city.fragment.SecondFragment;
import com.sky.city.fragment.ThirdFragment;
import com.sky.city.mvp.LoginConstract;
import com.sky.city.mvp.LoginPrecenter;
import com.sky.city.widget.BaseCircleView;
import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.RequestBody;

public class MainActivity extends BaseMvpActivity<LoginConstract.LoginView, LoginPrecenter> implements LoginConstract.LoginView {

    private static final String TAG = "MainActivity";

    @BindView(R.id.circleview)
    BaseCircleView circleview;

    @BindView(R.id.img_home)
    ImageView img_home;

    @BindView(R.id.img_sencond)
    ImageView img_sencond;

    @BindView(R.id.img_third)
    ImageView img_third;

    @BindView(R.id.img_four)
    ImageView img_four;

    @BindView(R.id.img_five)
    ImageView img_five;

    @BindView(R.id.mainContent)
    FrameLayout mainContent;

    private HomeFragment homeFragment;
    private SecondFragment secondFragment;
    private ThirdFragment thirdFragment;
    private FourFragment fourFragment;
    private FiveFragment fiveFragment;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_main;
    }

    @Override
    protected void beforeSetView() {
        super.beforeSetView();
        circleview.setColor(Color.parseColor("#ffff0000"));
        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f)
                .init();

        MultiLanguageUtil.getInstance().getCountryType(this);
//       setvideo();
        initFragment();
        juaasgeFragment(0);

    }

    @OnClick(R.id.click_btn)
    public void click_btn() {

        LanguageDialog languageDialog = new LanguageDialog(this, R.style.ActionSheetDialogStyle);
        languageDialog.show();

        RequestBody requestBody = JSONReqParams.construct()
                .put("type", "1")
                .put("mobile", "2")
                .put("pwd", "3")
                .buildRequestBody();

        getPresenter().login(requestBody);
    }

    @Override
    protected LoginPrecenter createPresenter() {
        return new LoginPrecenter();
    }


    @Override
    public void LoginSucess(Object Response) {

    }

    @Override
    public void LoginFailerd(String Response) {

    }

    @OnClick(R.id.img_home)
    public void img_home() {
        juaasgeFragment(0);
    }

    @OnClick(R.id.img_sencond)
    public void img_sencond() {
        juaasgeFragment(1);
    }

    @OnClick(R.id.img_third)
    public void img_third() {
        juaasgeFragment(2);
    }

    @OnClick(R.id.img_four)
    public void img_four() {
        juaasgeFragment(3);
    }

    @OnClick(R.id.img_five)
    public void img_five() {
        juaasgeFragment(4);
    }


    private void jussage(int position){
        switch (position) {
            case 0:
                img_home.setImageResource(R.mipmap.home_true);
                img_sencond.setImageResource(R.mipmap.category_false);
                img_third.setImageResource(R.mipmap.center_false);
                img_four.setImageResource(R.mipmap.bag_false);
                img_five.setImageResource(R.mipmap.my_false);
                break;
            case 1:
                img_home.setImageResource(R.mipmap.home_false);
                img_sencond.setImageResource(R.mipmap.category_true);
                img_third.setImageResource(R.mipmap.center_false);
                img_four.setImageResource(R.mipmap.bag_false);
                img_five.setImageResource(R.mipmap.my_false);
                break;
            case 2:
                img_home.setImageResource(R.mipmap.home_false);
                img_sencond.setImageResource(R.mipmap.category_false);
                img_third.setImageResource(R.mipmap.center_true);
                img_four.setImageResource(R.mipmap.bag_false);
                img_five.setImageResource(R.mipmap.my_false);
                break;
            case 3:
                img_home.setImageResource(R.mipmap.home_false);
                img_sencond.setImageResource(R.mipmap.category_false);
                img_third.setImageResource(R.mipmap.center_false);
                img_four.setImageResource(R.mipmap.bag_true);
                img_five.setImageResource(R.mipmap.my_false);
                break;
            case 4:
                img_home.setImageResource(R.mipmap.home_false);
                img_sencond.setImageResource(R.mipmap.category_false);
                img_third.setImageResource(R.mipmap.center_false);
                img_four.setImageResource(R.mipmap.bag_false);
                img_five.setImageResource(R.mipmap.my_true);
                break;
        }
    }

    private void initFragment() {
        homeFragment = HomeFragment.getInstance();
        secondFragment =SecondFragment.getInstance();
        thirdFragment = ThirdFragment.getInstance();
        fourFragment = FourFragment.getInstance();
        fiveFragment = FiveFragment.getInstance();
        getSupportFragmentManager().beginTransaction().add(R.id.mainContent, homeFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().add(R.id.mainContent, secondFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().add(R.id.mainContent, thirdFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().add(R.id.mainContent, fourFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().add(R.id.mainContent, fiveFragment).commitAllowingStateLoss();


    }


    private void hideFragment() {
        getSupportFragmentManager().beginTransaction().hide(homeFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().hide(secondFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().hide(thirdFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().hide(fourFragment).commitAllowingStateLoss();
        getSupportFragmentManager().beginTransaction().hide(fiveFragment).commitAllowingStateLoss();
    }

    private void juaasgeFragment(int index){
        switch (index) {
            case 0:
                hideFragment();
                jussage(0);
                getSupportFragmentManager().beginTransaction().show(homeFragment).commitAllowingStateLoss();
                break;
            case 1:
                hideFragment();
                jussage(1);
                getSupportFragmentManager().beginTransaction().show(secondFragment).commitAllowingStateLoss();
                break;
            case 2:
                hideFragment();
                jussage(2);
                getSupportFragmentManager().beginTransaction().show(thirdFragment).commitAllowingStateLoss();
                break;
            case 3:
                hideFragment();
                jussage(3);
                getSupportFragmentManager().beginTransaction().show(fourFragment).commitAllowingStateLoss();
                break;
            case 4:
                hideFragment();
                jussage(4);
                getSupportFragmentManager().beginTransaction().show(fiveFragment).commitAllowingStateLoss();
                break;
        }
    }

}